package com.base.cn.platform.os.controller.op.groom;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.service.manage.op.groom.OpGroomPlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 推荐位置后台Controller
 * @author ll
 * @since 2018/05/07
 */
@Controller
@RequestMapping("/admin/op/groom")
public class AdminOpGroomPlaceController extends AdminBaseController {
    @Autowired
    private OpGroomPlaceService opGroomPlaceService;

    /**
     * 添加修改推荐位置
     * @param groomPlace
     * @return
     */
    @RequestMapping("/ajaxSaveUpdateGroomPlace")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "修改推荐位置")
    public Map<String,Object> ajaxSaveUpdateGroomPlace(@RequestBody Map<String,Object> groomPlace){
        return  opGroomPlaceService.ajaxSaveUpdateGroomPlace(groomPlace);
    }

    /**
     * 搜索列表页面
     * @return
     */
    @RequestMapping("/queryGroomPlaceList")
    public String queryGroomPlaceList(Model model){
        return resultPage("/op/groom/groomplace_list");
    }

    /**
     * 搜索ajax列表
     * @param groomPlace
     * @return
     */
    @RequestMapping("/queryAjaxGroomPlaceListPage")
    public String queryAjaxGroomPlaceListPage(Model model,
                                                      @RequestParam(value = "currentPage",required = false,defaultValue = "1")Integer currentPage,
                                                      @RequestBody Map<String,Object> groomPlace){
        Map<String,Object> dataMap = opGroomPlaceService.queryAjaxGroomPlaceListPage(currentPage,groomPlace);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/op/groom/groomplace_ajax_list");
    }

    /**
     * 冻结，恢复,删除
     * @param groomPlaceIds
     * @param status
     * @return
     */
    @RequestMapping("/updateGroomPlaceStatusByIds")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "修改推荐位状态")
    public Map<String,Object> updateGroomPlaceStatusByIds(@RequestParam("groomPlaceIds")String groomPlaceIds,
                                                          @RequestParam("status")Integer status){
        if (StringUtils.isEmpty(groomPlaceIds)){
            return ResultUtil.ERROR("请选择操作的数据");
        }
        return opGroomPlaceService.updateGroomPlaceStatusByIds(groomPlaceIds,status);
    }

    /**
     * 获取推荐位置详情
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/opGroomPlaceInfoById")
    public String  opGroomPlaceInfoById(Model model,
                                        @RequestParam("id")BigDecimal id,
                                        @RequestParam(value = "status",required = false,defaultValue = "1")Integer status){
        Map<String,Object> map = opGroomPlaceService.groomPlaceInfo(id);
        model.addAttribute("groomPlace",map);
        model.addAttribute("status",status);
        if(status==1){
            return resultPage("/op/groom/groom_place_toSee");
        }else{
            return resultPage("/op/groom/groom_place_data_update");
        }
    }

    /**
     * 去添加页面修改页面
     */
    @RequestMapping("/toSaveOpGroomPlacePage")
    public String toSaveOpGroomPlacePage(Model model,
                                         @RequestParam(value = "id",required = false)BigDecimal id){
        Map<String,Object> groomPlace = new HashMap<>();
        if (DataUtil.idIsNotNull(id)){
            groomPlace = opGroomPlaceService.groomPlaceById(id);
        }
        model.addAttribute("groomPlace",groomPlace);
        return resultPage("/op/groom/save_update");
    }

    /**
     * 跳转到批量推荐
     * @return
     */
    @RequestMapping("/toGroomPlaceDataSave")
    public String  toGroomPlaceDataSave(){
        return resultPage("/op/groom/groom_place_data_save");
    }

    /**
     * 后台批量推荐搜索位置
     * @param dataType
     * @param status
     * @param isDataType
     * @return
     */
    @RequestMapping("/queryOpGroomPlaceByDataType")
    @ResponseBody
    public Map<String,Object> queryOpGroomPlaceByDataType(@RequestParam("dataType")String dataType,
                                                         @RequestParam(value = "status",required = false,defaultValue = "1")Integer status,
                                                         @RequestParam(value = "isDataType",required = false,defaultValue = "false")boolean isDataType){

        List<Map<String,Object>> dataMaps =opGroomPlaceService.queryOpGroomPlaceByDataType(dataType,status,isDataType);
        return ResultUtil.SUCCESS("查询成功",dataMaps);
    }

}
